package tgc.edu.ljc.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

@Entity
public class Course {
	private Integer id;
	private String name;
	private List<Student> students=new ArrayList<>();
	private List<Grade> grades=new ArrayList<>();
	public Course() {
		super();
	}
	
	public Course(Integer id, String name) {
		super();
		this.id = id;
		this.name = name;
	}
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	@Column(length=10)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	
	/*@ManyToMany
	@JoinTable(name="student_course",joinColumns= {@JoinColumn(name="cid")},inverseJoinColumns= {@JoinColumn(name="sid")})
	public List<Student> getStudents() {
		return students;
	}

	public void setStudents(List<Student> students) {
		this.students = students;
	}*/
	
	@Transient
	public List<Student> getStudents() {
		List<Student> students=new ArrayList<>();
		for (Grade grade : getGrades()) {
			students.add(grade.getStudent());
		}
		return students;
	}

	@OneToMany(mappedBy="course")
	public List<Grade> getGrades() {
		return grades;
	}

	public void setGrades(List<Grade> grades) {
		this.grades = grades;
	}

	public Course(Integer id) {
		super();
		this.id = id;
	}
	
}
